package c.x.jy.forkJoin;

import org.springframework.beans.factory.annotation.Autowired;

public class SingleThread {

	
	//@Autowired
	private DbUtil  db =new DbUtil();
	
	public final static int THRESHOLD= 1000;
	
	public void sum() {
		int recordMin =db.getMin();
		int recordMax =db.getMax();
		long sum =0;
		
		long start =System.currentTimeMillis();
		int fromId= recordMin;
		
		int endId = recordMin+THRESHOLD;

		while (endId <= recordMax) {
		   sum =sum+db.sumRecorders(fromId,endId);
		   
		   fromId =endId;
		   endId =endId+ THRESHOLD; 
			
		}
		
		//   sum =sum+db.sumRecorders(endId,recordMax);
		
		System.out.println("The sum is "+sum+" spend time: "+(System.currentTimeMillis()-start) +" ms"  +"  endId: "+endId  +"recordMin:"+recordMin+"  recordMax:"+recordMax );
	}
	
}
